#pragma once

#include <ctime>

class PerformanceTimer
{
public:
  PerformanceTimer() { reset(); }

  void start() { m_start = clock(); }
  
  void stop()
  {
    clock_t dt = clock() - m_start;
    if (dt > m_max) m_max = dt;
    if (dt < m_min) m_min = dt;
    m_total += dt;
    ++m_count;
  }

  void reset()
  {
    m_start = m_total = m_max = m_min = 0;
    m_count = 0;
  }

  float getTotalTime() const { return (float) m_total / CLOCKS_PER_SEC; }

  float getMaxTime() const { return (float) m_max / CLOCKS_PER_SEC; }

  float getMinTime() const { return (float) m_min / CLOCKS_PER_SEC; }

  float getMeanTime() const
  {
    return (m_count == 0) ? 0 : ((float) m_total / CLOCKS_PER_SEC / m_count);
  }

private:
  clock_t m_start;

  clock_t m_total;
  clock_t m_max;
  clock_t m_min;
  int m_count;
};